package nodetest;
/*/
 * why use an array if this is a "dynamic" stack implementation? 
 * dynamic is supposed to be growing and shrinking to whatever size you want
 * in this example the max size entered is 6.  * this relates to an array implementation 
 * of stacks... array is in consiquential, this could have been an application to take in n number of strings via JOptionPane.
 * it would then store this in a variable and that varaible pushed onto the dynamic data structure . it can be repeated as many times as nescesary
 * or as little times as nescessary making the stack as small or large as nescessary. 
 * all other functions work in this program based on the fact that the stack contains >1 item
 */

import javax.swing.JOptionPane;

public class NodeTest {

    private Object element;       // element stored in this node can be a string int etc
    private Node next;          // reference to the next node in the list      

    public static String[] reverseRead(String[] cities) throws StackException {// Create the Stack
        LinkedStack S = new LinkedStack();
        String[] b = new String[cities.length];
        for (int i = 0; i < cities.length; i++) {
            S.push(cities[i]);
        }
        for (int i = 0; i < cities.length; i++) {
            b[i] = (String) (S.pop());
        }

        return b;
    }

    public static String outputCities(String cities[]) {
        String output = "\n\nThe Order Of The Cities Are:\n";
        for (int i = 0; i < cities.length; i = i + 1) {
            output += " " + cities[i];
        }

        output += "\n";
        return output;
    } // end of outputCities

    public static void main(String[] args) throws StackException {
        String[] cities = {"Turin", "Limerick", "Iraklion", "Prague", "Memphis", "London"};
        String[] reversedCities = new String[cities.length];
        reversedCities = reverseRead(cities);
        String output = outputCities(cities);
        output += outputCities(reversedCities);
        JOptionPane.showMessageDialog(null, output, "Cities", JOptionPane.INFORMATION_MESSAGE);
        System.exit(0);
    } // end of main 
}
